<?php
function getSiteList($clientId = 0)
{
	$select = 'id, title';
	$where = '';
	if($clientId > 0)
	{
		$where = 'WHERE client_id='.$clientId;
	}
	$select = 'SELECT '.$select.' FROM '.DB_PERFIX.'sites '.$where.' ORDER BY title;'
	$result = mysql_query($select);
	while($row = mysql_fetch_array($result))
	{
		$item['id'] 			= $row['id'];
		$item['title'] 			= $row['title'];
	}
	return $item;
}

function getSiteSettingsAdmin($id = 1)
{
	$select = 'id, title, template, meta_data, meta_key, user_reg, user_reg_act, track_online, allow_image, allow_mp3, allow_video';
	$result = mysql_query('SELECT '.$select.' FROM '.DB_PERFIX.'sites WHERE id='.$id.' LIMIT 1;');
	while($row = mysql_fetch_array($result))
	{
		$site['id'] 			= $row['id'];
		$site['title'] 			= $row['title'];
		$site['meta_data'] 		= $row['meta_data'];
		$site['meta_key'] 		= $row['meta_key'];
	}
	
	if($template < 1)
	{ $template = 1; }
	$selection = 'SELECT * FROM '.DB_PERFIX.'themes WHERE id='.$template.' LIMIT 1;';
	
	$result = mysql_query($selection);
	while($row = mysql_fetch_array($result))
	{
		$site['id']					= $row['id'];
		$site['title'] 				= $row['title'];
		$site['site_id']			= $row['site_id'];
		$site['site_default'] 		= $row['site_default'];
		$site['theme_type']			= $row['theme_type'];
		$site['fixed_width']		= $row['fixed_width'];
		$site['horisontal_pos']		= $row['horisontal_pos'];
			
		$site['border_site']		= $row['border_site'];
		$site['border_content'] 	= $row['border_content'];
		$site['header']				= $row['header']; 
		$site['header_fixed']		= $row['header_fixed']; 
		$site['header_border'] 		= $row['header_border'];
		$site['header_hfb'] 		= $row['header_hfb'];
		$site['header_content'] 	= $row['header_content'];
		
		$site['footer']				= $row['footer'];
		$site['footer_border'] 		= $row['footer_border'];
		$site['footer_fixed']		= $row['footer_fixed']; 
		$site['footer_hfb'] 		= $row['footer_hfb'];
		$site['footer_content'] 	= $row['footer_content'];
		
		$site['col_left']			= $row['col_left'];
		$site['col_left_border'] 	= $row['col_left_border'];
		$site['col_left_hfb'] 		= $row['col_left_hfb'];
		$site['col_left_content'] 	= $row['col_left_content'];
		
		$site['col_right']			= $row['col_right'];
		$site['col_right_border'] 	= $row['col_right_border'];
		$site['col_right_hfb'] 		= $row['col_right_hfb'];
		$site['col_right_content'] 	= $row['col_right_content'];
		
		$site['hfb_set'] 			= $row['hfb_set'];
		$site['hfb_com_set'] 		= $row['hfb_com_set'];
		
		define('DEF_HFB', $site['hfb_set']);
	}
	if($site['bg'] > 0)
	{
		$result = mysql_query('SELECT * FROM '.DB_PERFIX.'backgrounds WHERE id='.$site['bg'].';');
		while($row = mysql_fetch_array($result))
		{$site['bg_file'] = $row['path'];}
	}
	return $site;
}

function getSiteTheme($template = 1)
{
	$selection = 'SELECT * FROM '.DB_PERFIX.'themes WHERE id='.$template.' LIMIT 1;';
	
	$result = mysql_query($selection);
	while($row = mysql_fetch_array($result))
	{
		$site['id']					= $row['id'];
		$site['title'] 				= $row['title'];
		$site['site_width']			= $row['site_width'];
		$site['site_allign'] 		= $row['site_allign'];
		$site['border'] 			= $row['border'];
		$site['header']				= $row['header']; 
		$site['header_fixed']		= $row['header_fixed']; 
		$site['content_border'] 	= $row['content_border'];
		$site['header_border'] 		= $row['header_border'];
		$site['header_hfb'] 		= $row['header_hfb'];
		$site['header_temp'] 		= $row['header_temp'];
		$site['footer']				= $row['footer'];
		$site['footer_fixed']		= $row['footer_fixed']; 
		$site['footer_border'] 		= $row['footer_border'];
		$site['footer_hfb'] 		= $row['footer_hfb'];
		$site['footer_temp'] 		= $row['footer_temp'];
		$site['col_left']			= $row['col_left'];
		$site['col_left_border'] 	= $row['col_left_border'];
		$site['col_left_hfb'] 		= $row['col_left_hfb'];
		$site['col_left_temp'] 		= $row['col_left_temp'];
		$site['col_left_width']		= $row['col_left_width'];
		$site['col_right']			= $row['col_right'];
		$site['col_right_border'] 	= $row['col_right_border'];
		$site['col_right_hfb'] 		= $row['col_right_hfb'];
		$site['col_right_temp'] 	= $row['col_right_temp'];
		$site['col_right_width']	= $row['col_right_width'];
		$site['bg']					= $row['bg'];
		$site['bg_style'] 			= $row['bg_style'];
		$site['hfb_set'] 			= $row['hfb_set'];
	}
	return $site;
}

function addSite($title)
{
	$insert  = "INSERT INTO ".DB_PERFIX."sites (`title`)"; 
	$insert .= "VALUES ('".$title."');";
	$result = mysql_query($insert);
}
function addSiteTemplate($title)
{
	$insert  = "INSERT INTO ".DB_PERFIX."site_templates (`title`)"; 
	$insert .= "VALUES ('".$title."');";
	$result = mysql_query($insert);
}
function copySiteTemplate($id)
{
	$site = getSiteTheme($id);
	$into  = '`title`, `site_width`, `site_allign`, `content_border`, ';
	$into .= '`header`, `header_temp`, `header_border`, ';
	$into .= '`footer`, `footer_temp`, `footer_border`, ';
	$into .= '`col_left`, `col_left_border`, `col_left_temp`, `col_left_width`, ';
	$into .= '`col_right`, `col_right_border`, `col_right_temp`, `col_right_width`, ';
	$into .= '`bg`, `bg_style`, `border`, `hfb_set`';
	
	$values = '"'.$site['title'].' Copy", ';
	$values .= '"'.$site['site_width'].'", ';
	$values .= '"'.$site['site_allign'].'", ';
	$values .= ''.$site['content_border'].', ';
	$values .= ''.$site['header'].', ';
	$values .= ''.$site['header_temp'].', ';
	$values .= ''.$site['header_border'].', ';
	$values .= ''.$site['footer'].', ';
	$values .= ''.$site['footer_temp'].', ';
	$values .= ''.$site['footer_border'].', ';
	$values .= ''.$site['col_left'].', ';
	$values .= ''.$site['col_left_border'].', ';
	$values .= ''.$site['col_left_temp'].', ';	
	$values .= ''.$site['col_left_width'].', ';
	$values .= ''.$site['col_right'].', ';
	$values .= ''.$site['col_right_border'].', ';
	$values .= ''.$site['col_right_temp'].', ';	
	$values .= ''.$site['col_right_width'].', ';
	$values .= ''.$site['bg'].', ';
	$values .= '"'.$site['bg_style'].'", ';
	$values .= ''.$site['border'].', ';	
	$values .= ''.$site['hfb_set'].' ';
	
	$insert  = 'INSERT INTO '.DB_PERFIX.'themes ('.$into.')'; 
	$insert .= 'VALUES ('.$values.');';
	$result = mysql_query($insert);
	echo $insert;
}
?>